package com.backend.demo.tag;

import java.util.List;

import javax.servlet.jsp.JspWriter;

import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.backend.demo.dao.MenuDao;
import com.backend.demo.entities.Menu;

/**
 * 获得子菜单
 * @author Administrator
 *
 */
public class MenuSubItemTag extends RequestContextAwareTag {

	private static final long serialVersionUID = 1L;
	
	private String cssClass;
	
	private String cssId;
	
	private Long menuID;
	
	private MenuDao menuDao;
	
	private String onclick;
	
	private String language;
	
	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public String getCssClass() {
		return cssClass;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public String getCssId() {
		return cssId;
	}

	public void setCssId(String cssId) {
		this.cssId = cssId;
	}

	public Long getMenuID() {
		return menuID;
	}

	public void setMenuID(Long menuID) {
		this.menuID = menuID;
	}
	
	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}
	
	public String getOnclick() {
		return onclick;
	}

	@Override
	protected int doStartTagInternal() throws Exception {
		menuDao = (MenuDao) this.getRequestContext().getWebApplicationContext().getBean("menuDao");
		List<Menu> menus = menuDao.getMenusByParentID(menuID);
		JspWriter jspWriter = pageContext.getOut();
		StringBuffer stringBuffer = new StringBuffer("<ul class='nav nav-second-level'>");
		if(menus != null && menus.size() > 0 ){
			for (int i = 0; i < menus.size(); i++) {
				if("zh_CN".equals(language)){
					stringBuffer.append("<li><a class=\"J_menuItem\" onclick=\"ajaxDiv('content', '"+menus.get(i).getUrl()+"')\">"+menus.get(i).getMenu_zh_name()+"</a></li>");
				}else{
					stringBuffer.append("<li><a class=\"J_menuItem\" onclick=\"ajaxDiv('content', '"+menus.get(i).getUrl()+"')\">"+menus.get(i).getMenu_en_name()+"</a></li>");
				}
			}
		}
		stringBuffer.append("</ul>");
		jspWriter.print(stringBuffer.toString());
		return 0;
	}

}
